package com.hxzy.service.impl;

import com.hxzy.util.MybatisUtil;
import com.hxzy.dto.PlotInfoDTO;
import com.hxzy.entity.PlotInfo;
import com.hxzy.mapper.PlotMapper;
import com.hxzy.service.PlotService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Description:
 * @Author: ykj
 * @Date: 2022/2/28 14:40
 */
public class PlotServiceImpl implements PlotService {
    @Override
    public int insert(PlotInfo plotInfo) {
        int insert=-1;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            PlotMapper mapper = sqlSession.getMapper(PlotMapper.class);
            insert= mapper.insert(plotInfo);
            sqlSession.commit();
        }
        return insert;
    }

    @Override
    public int update(PlotInfo plotInfo) {
       int count=1;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            PlotMapper mapper = sqlSession.getMapper(PlotMapper.class);
            int update = mapper.update(plotInfo);
            sqlSession.commit();
        }
       return count;
    }

    @Override
    public int delete(String id) {
        int count = -1;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            PlotMapper mapper = sqlSession.getMapper(PlotMapper.class);
            count = mapper.delete(id);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public PlotInfo findOne(String id) {
        return null;
    }

    @Override
    public List<PlotInfo> search(PlotInfoDTO plotInfoDTO) {
        List<PlotInfo> search=null;
       try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
           PlotMapper mapper = sqlSession.getMapper(PlotMapper.class);
            search = mapper.search(plotInfoDTO);
       }
       return search;
    }
}
